02 / 10

How do you list running containers?

You list running containers using the docker ps command, which shows all active containers with their IDs, names, images, status, and port mappings.

The docker ps command is the primary tool for listing Docker containers. Without any flags, it displays only running containers, showing essential information such as container ID, image used, command being executed, creation time, current status, port mappings, and container name. For debugging or auditing purposes, you can expand this view to include stopped containers or format the output for scripting.

Basic Container Listing Commands

The -a or --all flag is crucial when you need to see stopped containers, which are not shown by default. Stopped containers consume disk space and can accumulate over time. The -q flag returns only numeric container IDs, which pairs well with other commands like docker stop $(docker ps -q) to stop all running containers, or docker rm $(docker ps -a -q) to clean up all stopped containers.

Docker's filtering capability (--filter) allows you to narrow results by various criteria: status (running, exited, paused), name, label, network, or exited code. For example, docker ps --filter "exited=1" shows containers that exited with error code 1. You can combine multiple filters to refine results further.

Common Use Cases
  1. 1

    docker ps - Quick check of what's currently running

  2. 2

    docker ps -a - See all containers, including stopped ones (disk usage)

  3. 3

    docker ps -a --size - Check disk space consumed by containers

  4. 4

    docker ps -q - Get IDs for scripting (e.g., docker stop $(docker ps -q))

  5. 5

    docker ps --filter "name=postgres" - Find containers related to a specific service

  6. 6

    docker ps --format "table {{.Names}}\t{{.Image}}" - Clean output for monitoring dashboards

The output columns include: CONTAINER ID (shortened unique identifier), IMAGE (image name:tag), COMMAND (command being executed), CREATED (time since creation), STATUS (running, exited, etc.), PORTS (port mappings), and NAMES (container names). The STATUS column is particularly useful for understanding container health—Up 2 minutes indicates healthy operation, while Exited (1) 3 hours ago shows a failure with the exit code.

Difficulty: 2/10
Topics: docker CLI, container monitoring, process inspection

Scenario Questions

0-2 years experience
  1. 1

    You need to verify which containers are currently running on your laptop before starting a new service. Which Docker command do you run and what does the output look like?

  2. 2

    If you execute docker ps and see an empty list, what are the possible reasons?

  3. 3

    How would you list only the IDs of the running containers in a script?

2-5 years experience
  1. 1

    During a CI build a test fails because a dependent database container isn’t up. Walk me through how you would check the running containers and diagnose the issue.

  2. 2

    Your docker ps output is cluttered with stopped containers. How would you modify the command to show only the active ones and why is that helpful?

  3. 3

    Explain why using docker ps -a might mislead you when you’re trying to confirm a service is running.

5-8 years experience
  1. 1

    In production you have hundreds of containers across many hosts. How would you design a reliable way to list all running containers fleet‑wide?

  2. 2

    Your monitoring pipeline parses docker ps output, but it’s becoming a performance bottleneck. What alternatives or optimizations would you consider?

  3. 3

    If you need to list running containers that match a specific label pattern at scale, how would you construct the command and what trade‑offs does it introduce?

8+ years experience
  1. 1

    Your org is migrating from ad‑hoc Docker CLI usage to a centralized orchestration platform. How would you phase out reliance on docker ps in operational tooling while preserving visibility for teams?

  2. 2

    When building a cross‑team observability platform, how would you abstract container‑listing functionality to support Docker, containerd, and CRI‑O, and what architectural concerns arise?

  3. 3

    Discuss the long‑term maintenance risks of embedding raw docker ps calls in scripts used across many services, and propose a strategy to reduce technical debt.

Follow-up Questions

  • Which flag would you add to see just the container IDs?
  • How would you filter the list to only containers with a specific label?
  • What would you do if `docker ps` returns a permission error on a CI runner?